package com.nami.gchat.app.dubbo;

import com.nami.basic.dto.MultiResponse;
import com.nami.gchat.client.api.GrpMemberClient;
import com.nami.gchat.client.response.GrpMemberDTO;
import com.nami.gchat.domain.model.co.GrpMemberModel;
import com.nami.gchat.domain.repository.GrpMemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.common.core.utils.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@DubboService
@RequiredArgsConstructor
public class GrpMemberClientImpl implements GrpMemberClient {

    private final GrpMemberRepository grpMemberRepository;

    @Override
    public MultiResponse<GrpMemberDTO> getGroupMembers(String grpId) {
        return null;
    }

    @Override
    public MultiResponse<String> listOfUserIdsByGrpMemberQry(String grpId) {
        if (StringUtils.isBlank(grpId)) {
            return MultiResponse.buildFailure("400", "");
        }
        List<GrpMemberModel> grpMemberModels = grpMemberRepository.getGrpMembersFromCacheOrDB(grpId);
        List<String> result = grpMemberModels.stream().map(GrpMemberModel::getUserId).collect(Collectors.toList());
        return MultiResponse.of(result);
    }
}
